const app = getApp();
// const CONFIG = require('../../config.js')
// const WXAPI = require('apifm-wxapi')

Page({
    data:{
      orderId:0,
      goodsList:[]
    },
    onLoad:function(options){
      // e.id = 478785
      // var orderId = e.id;
      const orderdetail = JSON.parse(decodeURIComponent(options.orderdetail));
      console.log(orderdetail)
       this.setData({
        orderDetail: orderdetail,
        goodsList: orderdetail.goodsinfo
      });
    },
    onShow : function () {
      var that = this;
      // WXAPI.orderDetail(wx.getStorageSync('token'), that.data.orderId).then(function (res) {
      //   if (res.code != 0) {
      //     wx.showModal({
      //       title: '错误',
      //       content: res.msg,
      //       showCancel: false
      //     })
      //     return;
      //   }
      //   // 绘制核销码
      //   if (res.data.orderInfo.hxNumber && res.data.orderInfo.status > 0) {
      //     wxbarcode.qrcode('qrcode', res.data.orderInfo.hxNumber, 650, 650);
      //   }
      //
      //   that.setData({
      //     orderDetail: res.data
      //   });
      // })
      // 子快递单信息
      if (that.data.delivery_info) {
        that.data.delivery_info.forEach(ele => {
          if (ele.traces) {
            ele.tracesArray = JSON.parse (ele.traces)
            if (ele.tracesArray && ele.tracesArray.length > 0) {
              ele.tracesLast = ele.tracesArray[ele.tracesArray.length - 1].AcceptStation + '\n' + ele.tracesArray[ele.tracesArray.length - 1].AcceptTime
            }
          }
        })
      }
    },
    wuliuDetailsTap:function(e){
      var orderId = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: "/pages/wuliu/index?id=" + orderId
      })
    },
    confirmBtnTap:function(e){

    },
    async submitReputation(e) {

    },
    afterPicRead(e) {
      const idx = e.currentTarget.dataset.idx
      let picsList = this.data.picsList
      if (!picsList) {
        picsList = []
        for (let index = 0; index < this.data.orderDetail.goods.length; index++) {
          picsList[index] = []
        }
      }
      picsList[idx] = picsList[idx].concat(e.detail.file)
      this.setData({
        picsList
      })
    },
    afterPicDel(e) {
      const idx = e.currentTarget.dataset.idx
      let picsList = this.data.picsList
      picsList[idx].splice(e.detail.index, 1)
      this.setData({
        picsList
      })
    }
})